package com.menggudf.dao;

import com.menggudf.dao.base.BaseDaoImpl;
import com.menggudf.dao.base.BaseQuery;
import com.menggudf.dao.base.Page;
import com.menggudf.entity.BlackList;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Repository;

@Repository
public class BlackListDao
  extends BaseDaoImpl<BlackList>
{
  private static final Log log = LogFactory.getLog(BlackListDao.class);
  @PersistenceContext(unitName="medicalUnit")
  private EntityManager entityManager;
  
  public void persist(BlackList transientInstance)
  {
    try
    {
      this.entityManager.persist(transientInstance);
    }
    catch (RuntimeException re)
    {
      log.error("persist failed", re);
      throw re;
    }
  }
  
  public void remove(BlackList persistentInstance)
  {
    try
    {
      this.entityManager.remove(persistentInstance);
    }
    catch (RuntimeException re)
    {
      log.error("remove failed", re);
      throw re;
    }
  }
  
  public BlackList merge(BlackList detachedInstance)
  {
    try
    {
      return (BlackList)this.entityManager.merge(detachedInstance);
    }
    catch (RuntimeException re)
    {
      log.error("merge failed", re);
      throw re;
    }
  }
  
  public BlackList findById(Integer id)
  {
    try
    {
      return (BlackList)this.entityManager.find(BlackList.class, id);
    }
    catch (RuntimeException re)
    {
      log.error("get failed", re);
      throw re;
    }
  }
  
  @Deprecated
  public Page<BlackList> getBlackList(String num, Integer type, int pageSize, int offset)
  {
    try
    {
      BaseQuery<BlackList> baseQuery = new BaseQuery(BlackList.class, getEntityManager());
      baseQuery.eq("num", num);
      baseQuery.eq("type", type);
      return listPage(BlackList.class, baseQuery, pageSize, offset);
    }
    catch (Exception e)
    {
      log.error("getBlackListList fail", e);
    }
    return new Page();
  }
}
